﻿#region References
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CdcSoftware.Pivotal.Applications.Core.Client;
using CdcSoftware.Pivotal.Engine.UI.Forms;
using System.Windows.Forms;
using System.Security.Cryptography;
using CdcSoftware.Pivotal.Engine.Client.Services.Interfaces;
using System.Data;
using CdcSoftware.Pivotal.Engine.Types.Database;
using CdcSoftware.Pivotal.Engine.Types.MailMerges;
using CdcSoftware.Pivotal.Applications.Core.Common;
using CdcSoftware.Pivotal.Engine;
using CdcSoftware.Pivotal.Engine.Types.DataTemplates;
using CdcSoftware.Pivotal.Engine.Client.Types;
#endregion

namespace Pcm.Retail.Client.FormTasks
{
    public partial class RE_Authorization : FormClientTask
    {        
        /// <summary>
        /// Event gets triggered with the change of Authorize All checkbox.
        /// </summary>
        /// <param name="sender">The control associated with the event triggered</param>
        /// <param name="args">The argument for the event</param>
        /// <history>
        /// #Revision   Date            Author      Description
        /// 6.0.9.1     2011-11-18      DS          Initial version for Retail.
        /// </history>
        public virtual void OnCheckAuthorizeAll(object sender, EventArgs args)
        {
            try
            {
                foreach (DataGridViewRow dgvr in ((DataGridView)this.FormControl.GetSecondary("RE_Authorization_Order_Id").WindowsControl).Rows)
                {
                    ((DataGridViewCheckBoxCell)dgvr.Cells["Authorized"]).Value = ((PivotalCheckBox)sender).Checked;
                }
            }
            catch (Exception ex)
            {
                Globals.HandleException(ex, true);
            }
        }

        /// <summary>
        /// On press of key Alt+R, execute the Authorize_OnClick event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public virtual void FormKeyDown(PivotalControl sender, EventArgs argsEA)
        {
            try
            {
                 KeyEventArgs args = argsEA as KeyEventArgs;

                 if (Control.ModifierKeys == Keys.Alt && args.KeyCode == Keys.R)
                 {
                     CommandHandlers.RE_AuthorizationCommandHandlers authorizationCommandHandler = new CommandHandlers.RE_AuthorizationCommandHandlers();
                     authorizationCommandHandler.Authorize_OnClick();
                 }
            }
            catch (Exception ex)
            {
                Globals.HandleException(ex, true);
            }
        }
    }
}
